using System.Collections.Generic;

namespace PKGames.Localization
{
	public sealed class Region : TypeSafeEnum
	{
		public enum RegionEnum
		{
			Brazil,
			UnitedStates
		}

		public static readonly Region Brazil = new Region(0, "BR");

		public static readonly Region UnitedStates = new Region(1, "US");

		private static Dictionary<string, Region> _dictionary = new Dictionary<string, Region>
		{
			{
				Brazil.ToString(),
				Brazil
			},
			{
				UnitedStates.ToString(),
				UnitedStates
			}
		};

		private static readonly Region[] _array = new Region[2]
		{
			Brazil,
			UnitedStates
		};

		public static Region[] Elements => _array;

		private Region(int value, string name)
			: base(value, name)
		{
		}

		public static Region FromString(string name)
		{
			if (_dictionary.ContainsKey(name))
			{
				return _dictionary[name];
			}
			throw new RegionNotSupportedException($"Error - the region \"{name}\" is not supported.");
		}

		public static Region FromInt(int value)
		{
			if (_array.Length > value)
			{
				return _array[value];
			}
			throw new RegionNotSupportedException($"Error - the region \"{value}\" is not supported.");
		}
	}
}
